package com.atguigu.gulimall.ssoclient.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * 2022/4/16 16:22 星期六
 * HelloController
 * Created by ASIA 乔帅阳 .
 * --
 * --
 */
@Controller
public class HelloController {


    /**
     * 无需登录可访问
     * @return
     */
    @GetMapping("/hello")
    public String hello(){

        return "hello";
    }

    /**
     *  受保护的，需要登录
     */
    @GetMapping("/employees")
    public String employees(Model model, HttpSession session){
        Object loginUser = session.getAttribute("loginUser");
        if(loginUser==null){
           //没登录，跳转到登录服务器进行登录
            return "";
        }else {
        List<String> emps = new ArrayList<>();
        emps.add("张三");
        emps.add("李四");
        model.addAttribute("emps",emps);
        return "list";
        }
    }

}
